package com.mineoj.mapper;

import com.mineoj.model.entity.QuestionSubmit;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

/**
* @author 明月
* @description 针对表【question_submit(题目提交)】的数据库操作Mapper
* @createDate 2025-04-01 16:06:47
* @Entity com.mineoj.model.entity.QuestionSubmit
*/
public interface QuestionSubmitMapper extends BaseMapper<QuestionSubmit> {
    /**
     * 获取用户提交统计（通过率/各状态计数）
     */
    @Select("SELECT " +
            "COUNT(*) AS total, " +
            "SUM(CASE WHEN status = 2 THEN 1 ELSE 0 END) AS success, " +
            "SUM(CASE WHEN status = 3 THEN 1 ELSE 0 END) AS fail " +
            "FROM question_submit " +
            "WHERE user_id = #{userId} AND is_delete = 0")
    Map<String, Long> getUserSubmitStatistics(@Param("userId") Long userId);

}




